#ifndef __OLED_H
#define __OLED_H

#include "main.h"

typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned long u32;
#define OLED_MODE 0
#define SIZE 6
#define XLevelL 0x00
#define XLevelH 0x10
#define Max_Column 128
#define Max_Row 64
#define Brightness 0xFF
#define X_WIDTH 128
#define Y_WIDTH 64
//**************************OLED IIC端口定义**************************

#define OLED_SCLK_Clr() HAL_GPIO_WritePin(ST_SCL0_GPIO_Port, ST_SCL0_Pin, GPIO_PIN_RESET) // SCL IIC接口的时钟信号
#define OLED_SCLK_Set() HAL_GPIO_WritePin(ST_SCL0_GPIO_Port, ST_SCL0_Pin, GPIO_PIN_SET)

#define OLED_SDIN_Clr() HAL_GPIO_WritePin(ST_SDA0_GPIO_Port, ST_SDA0_Pin, GPIO_PIN_RESET) // SDA IIC接口的数据信号
#define OLED_SDIN_Set() HAL_GPIO_WritePin(ST_SDA0_GPIO_Port, ST_SDA0_Pin, GPIO_PIN_SET)

#define OLED_READ_SDA() HAL_GPIO_ReadPin(ST_SDA0_GPIO_Port, ST_SDA0_Pin)

#define OLED_CMD 0  // 写命令
#define OLED_DATA 1 // 写数据

// OLED控制用函数
void OLED_WR_Byte(unsigned dat, unsigned cmd);
void OLED_Display_On(void);
void OLED_Display_Off(void);
void OLED_Init(void);
void OLED_Clear(void);
// void OLED_DrawPoint(u8 x, u8 y, u8 t);
// void OLED_Fill(u8 x1, u8 y1, u8 x2, u8 y2, u8 dot);
void OLED_ShowChar(u8 x, u8 y, u8 chr);
void OLED_ShowNum(u8 x, u8 y, u32 num, u8 len, u8 size);
void OLED_ShowString(u8 x, u8 y, const char *p);
void OLED_Set_Pos(unsigned char x, unsigned char y);
void OLED_ShowCHinese(u8 x, u8 y, u8 no);
void OLED_DrawBMP(unsigned char x0, unsigned char y0, unsigned char x1, unsigned char y1, unsigned char BMP[]);
// void Delay_50ms(unsigned int Del_50ms);
// void Delay_1ms(unsigned int Del_1ms);
void Delay_us(uint32_t us);
void fill_picture(unsigned char fill_Data);
void Write_IIC_Command(unsigned char IIC_Command);
void Write_IIC_Data(unsigned char IIC_Data);
void Write_IIC_Byte(unsigned char IIC_Byte);
void Adjust_I2C_Timing(bool increase);
uint8_t Get_I2C_Delay_Factor(void);
#endif
